package com.huawei.M01.iterator;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 111
 */
public class DecodeMessage {
    public String decodeMessage(String key, String message) {
        Map<String, Integer> keyMap = new HashMap<>();
        int index = 0;
        for (int i = 0; i < key.length(); i++) {
            if (key.charAt(i) != ' ' && !keyMap.containsKey(String.valueOf(key.charAt(i)))) {
                keyMap.put(String.valueOf(key.charAt(i)), index++);
            }
            if (index == 26) {
                break;
            }
        }
        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0; i < message.length(); i++) {
            if (message.charAt(i) == ' ') {
                stringBuilder.append(" ");
                continue;
            }
            stringBuilder.append((char) (keyMap.get(String.valueOf(message.charAt(i))) + 97));
        }
        return stringBuilder.toString();
    }

    public static void main(String[] args) {
        DecodeMessage decodeMessage = new DecodeMessage();
        System.out.println(decodeMessage.decodeMessage("the quick brown fox jumps over the lazy dog", "vkbs bs t suepuv"));
    }
}
